package cn.doit.scala.day02.map;

import scala.Int;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @DATE 2021/12/25/17:19
 * @Author MDK
 * @Version 2021.2.2
 **/
public class WordCount {
    public static void main(String[] args) throws IOException {
        HashMap<String, Integer> mp = new HashMap<>();
        //读取数据
        BufferedReader br = new BufferedReader(new FileReader("d://aa//1.txt"));
        String line = null;
        while ((line = br.readLine())!=null){
            String[] words = line.split("\\s+");
            for (String word : words) {
                Integer cnt = mp.getOrDefault(word, 0);
                mp.put(word, ++cnt);
            }
        }
        for (Map.Entry<String, Integer> entry : mp.entrySet()) {
            System.out.println(entry);
        }
        //关流
        br.close();
    }
}
